/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aptech.forms.nhanh;

import com.aptech.beans.Suppliers;
import com.aptech.dao.SupplierManager;
import com.aptech.validate.AccountValidator;
import com.aptech.validate.CustomerValidator;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Anh Nguyen
 */
public class SupplierList extends javax.swing.JFrame {

    private String flag = "";
    /**
     * Creates new form SupplierList
     */
    public SupplierList() throws Exception {
        initComponents();
        setLocationRelativeTo(null);
        loadData();
    }

    class ComboItem {

        private String key;
        private String value;

        public ComboItem(String key, String value) {
            this.key = key;
            this.value = value;
        }

        @Override
        public String toString() {
            return key;
        }

        public String getKey() {
            return key;
        }

        public String getValue() {
            return value;
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jdSuppList_InsertUpdate = new javax.swing.JDialog();
        jPanel1 = new javax.swing.JPanel();
        jlblSuppList_Name = new javax.swing.JLabel();
        jtfSuppList_Name = new javax.swing.JTextField();
        jlblSuppList_Address = new javax.swing.JLabel();
        jtfSuppList_Phone = new javax.swing.JTextField();
        jlblSuppList_Phone = new javax.swing.JLabel();
        jtfSuppList_Email = new javax.swing.JTextField();
        jlblSuppList_Email = new javax.swing.JLabel();
        jlblSuppList_TypeID = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtaSuppList_Address = new javax.swing.JTextArea();
        cbTypeID = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jbtSuppList_Submit = new javax.swing.JButton();
        jbtSuppList_Reset = new javax.swing.JButton();
        jdSuppList_Notification = new javax.swing.JDialog();
        jLabel10 = new javax.swing.JLabel();
        jlblAddress = new javax.swing.JLabel();
        jlblEmail = new javax.swing.JLabel();
        jlblPhone = new javax.swing.JLabel();
        jlblName = new javax.swing.JLabel();
        jlblStatus_Name = new javax.swing.JLabel();
        jlblStatus_Phone = new javax.swing.JLabel();
        jlblStatus_Address = new javax.swing.JLabel();
        jlblStatus_Email = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jbtInsert = new javax.swing.JButton();
        jbtUpdate = new javax.swing.JButton();
        jbtDelete = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbSupplierList = new javax.swing.JTable();

        jdSuppList_InsertUpdate.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jdSuppList_InsertUpdate.setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Information", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14), new java.awt.Color(255, 0, 0))); // NOI18N

        jlblSuppList_Name.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jlblSuppList_Name.setForeground(new java.awt.Color(51, 0, 255));
        jlblSuppList_Name.setText("Name");

        jtfSuppList_Name.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jtfSuppList_Name.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfSuppList_NameActionPerformed(evt);
            }
        });

        jlblSuppList_Address.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jlblSuppList_Address.setForeground(new java.awt.Color(51, 0, 255));
        jlblSuppList_Address.setText("Address");

        jtfSuppList_Phone.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N

        jlblSuppList_Phone.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jlblSuppList_Phone.setForeground(new java.awt.Color(51, 0, 255));
        jlblSuppList_Phone.setText("Phone");

        jtfSuppList_Email.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N

        jlblSuppList_Email.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jlblSuppList_Email.setForeground(new java.awt.Color(51, 0, 255));
        jlblSuppList_Email.setText("Email");

        jlblSuppList_TypeID.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jlblSuppList_TypeID.setForeground(new java.awt.Color(51, 0, 255));
        jlblSuppList_TypeID.setText("Type");

        jtaSuppList_Address.setColumns(20);
        jtaSuppList_Address.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jtaSuppList_Address.setRows(5);
        jScrollPane2.setViewportView(jtaSuppList_Address);

        cbTypeID.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jlblSuppList_Name, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jlblSuppList_Address, javax.swing.GroupLayout.Alignment.TRAILING)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jlblSuppList_Phone, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jlblSuppList_Email, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jlblSuppList_TypeID, javax.swing.GroupLayout.Alignment.TRAILING))))
                .addGap(61, 61, 61)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                        .addComponent(jtfSuppList_Phone)
                        .addComponent(jtfSuppList_Email)
                        .addComponent(jtfSuppList_Name))
                    .addComponent(cbTypeID, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(37, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblSuppList_Name)
                    .addComponent(jtfSuppList_Name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlblSuppList_Address)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfSuppList_Phone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblSuppList_Phone))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfSuppList_Email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblSuppList_Email))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblSuppList_TypeID)
                    .addComponent(cbTypeID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/029.png"))); // NOI18N

        jbtSuppList_Submit.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jbtSuppList_Submit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/003.png"))); // NOI18N
        jbtSuppList_Submit.setText("Submit");
        jbtSuppList_Submit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtSuppList_SubmitActionPerformed(evt);
            }
        });

        jbtSuppList_Reset.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jbtSuppList_Reset.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/016.png"))); // NOI18N
        jbtSuppList_Reset.setText("Reset");
        jbtSuppList_Reset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtSuppList_ResetActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jdSuppList_InsertUpdateLayout = new javax.swing.GroupLayout(jdSuppList_InsertUpdate.getContentPane());
        jdSuppList_InsertUpdate.getContentPane().setLayout(jdSuppList_InsertUpdateLayout);
        jdSuppList_InsertUpdateLayout.setHorizontalGroup(
            jdSuppList_InsertUpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jdSuppList_InsertUpdateLayout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(jdSuppList_InsertUpdateLayout.createSequentialGroup()
                .addGap(75, 75, 75)
                .addComponent(jbtSuppList_Submit)
                .addGap(44, 44, 44)
                .addComponent(jbtSuppList_Reset)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jdSuppList_InsertUpdateLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel9)
                .addGap(168, 168, 168))
        );
        jdSuppList_InsertUpdateLayout.setVerticalGroup(
            jdSuppList_InsertUpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jdSuppList_InsertUpdateLayout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabel9)
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(44, 44, 44)
                .addGroup(jdSuppList_InsertUpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtSuppList_Submit)
                    .addComponent(jbtSuppList_Reset))
                .addContainerGap(88, Short.MAX_VALUE))
        );

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel10.setForeground(new java.awt.Color(153, 0, 153));
        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/031.png"))); // NOI18N
        jLabel10.setText("Notification");
        jLabel10.setToolTipText("");

        jlblAddress.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlblAddress.setForeground(new java.awt.Color(255, 102, 102));
        jlblAddress.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jlblAddress.setText("Address:");

        jlblEmail.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlblEmail.setForeground(new java.awt.Color(255, 102, 102));
        jlblEmail.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jlblEmail.setText("Email:");

        jlblPhone.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlblPhone.setForeground(new java.awt.Color(255, 102, 102));
        jlblPhone.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jlblPhone.setText("Phone:");

        jlblName.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlblName.setForeground(new java.awt.Color(255, 102, 102));
        jlblName.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jlblName.setText("Name:");

        jlblStatus_Name.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlblStatus_Name.setForeground(new java.awt.Color(102, 102, 102));
        jlblStatus_Name.setText("field");

        jlblStatus_Phone.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlblStatus_Phone.setForeground(new java.awt.Color(102, 102, 102));
        jlblStatus_Phone.setText("field");

        jlblStatus_Address.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlblStatus_Address.setForeground(new java.awt.Color(102, 102, 102));
        jlblStatus_Address.setText("field");

        jlblStatus_Email.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlblStatus_Email.setForeground(new java.awt.Color(102, 102, 102));
        jlblStatus_Email.setText("field");

        javax.swing.GroupLayout jdSuppList_NotificationLayout = new javax.swing.GroupLayout(jdSuppList_Notification.getContentPane());
        jdSuppList_Notification.getContentPane().setLayout(jdSuppList_NotificationLayout);
        jdSuppList_NotificationLayout.setHorizontalGroup(
            jdSuppList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdSuppList_NotificationLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jdSuppList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jlblEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblName, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblPhone, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 198, Short.MAX_VALUE)
                .addGroup(jdSuppList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jdSuppList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jlblStatus_Phone)
                        .addComponent(jlblStatus_Email))
                    .addComponent(jlblStatus_Name, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jlblStatus_Address, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
            .addGroup(jdSuppList_NotificationLayout.createSequentialGroup()
                .addGap(84, 84, 84)
                .addComponent(jLabel10)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jdSuppList_NotificationLayout.setVerticalGroup(
            jdSuppList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdSuppList_NotificationLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel10)
                .addGap(40, 40, 40)
                .addGroup(jdSuppList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblName, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblStatus_Name))
                .addGap(18, 18, 18)
                .addGroup(jdSuppList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblStatus_Address))
                .addGap(13, 13, 13)
                .addGroup(jdSuppList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblPhone, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblStatus_Phone))
                .addGap(18, 18, 18)
                .addGroup(jdSuppList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblStatus_Email))
                .addContainerGap(77, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Suppliers Management");
        setIconImage(new ImageIcon(getClass().getResource("/com/image/icon.png")).getImage());

        jLabel1.setFont(new java.awt.Font("Segoe UI Light", 1, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 0, 0));
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/037.png"))); // NOI18N
        jLabel1.setText("Suppliers Management");

        jbtInsert.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jbtInsert.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/026.png"))); // NOI18N
        jbtInsert.setText("Insert");
        jbtInsert.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtInsertActionPerformed(evt);
            }
        });

        jbtUpdate.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jbtUpdate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/027.png"))); // NOI18N
        jbtUpdate.setText("Update");
        jbtUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtUpdateActionPerformed(evt);
            }
        });

        jbtDelete.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jbtDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/028.png"))); // NOI18N
        jbtDelete.setText("Delete");
        jbtDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtDeleteActionPerformed(evt);
            }
        });

        jtbSupplierList.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jtbSupplierList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "Name", "Type", "Address", "Phone", "Email"
            }
        ));
        jtbSupplierList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(jtbSupplierList);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(106, 106, 106)
                        .addComponent(jbtInsert)
                        .addGap(73, 73, 73)
                        .addComponent(jbtUpdate)
                        .addGap(71, 71, 71)
                        .addComponent(jbtDelete))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(176, 176, 176)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 338, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(122, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 707, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 287, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtInsert)
                    .addComponent(jbtUpdate)
                    .addComponent(jbtDelete))
                .addGap(41, 41, 41))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(117, 117, 117)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(118, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtInsertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtInsertActionPerformed
        // TODO add your handling code here:
        jdSuppList_InsertUpdate.setVisible(true);
        jdSuppList_InsertUpdate.pack();
        jdSuppList_InsertUpdate.setLocationRelativeTo(null);
        jtfSuppList_Name.setEditable(true);
        flag = "insert";
        clearForm();
    }//GEN-LAST:event_jbtInsertActionPerformed

    private void jbtSuppList_ResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtSuppList_ResetActionPerformed
        // TODO add your handling code here:
        clearForm();
    }//GEN-LAST:event_jbtSuppList_ResetActionPerformed

    private void jbtSuppList_SubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtSuppList_SubmitActionPerformed
        // TODO add your handling code here:
        boolean checkName = AccountValidator.validateSupplierName(jtfSuppList_Name.getText().trim());
        boolean checkAddress = AccountValidator.validateAddress(jtaSuppList_Address.getText().trim());
        boolean checkEmail = AccountValidator.validateEmail(jtfSuppList_Email.getText().trim());
        boolean checkPhone = CustomerValidator.checkPhone(jtfSuppList_Phone.getText().trim());
        try {
            //Get data
            Suppliers supplier = new Suppliers();

            supplier.setSupplierName(jtfSuppList_Name.getText().trim());
            supplier.setSupplierAddress(jtaSuppList_Address.getText().trim());
            supplier.setSupplierPhone(jtfSuppList_Phone.getText().trim());
            supplier.setSupplierEmail(jtfSuppList_Email.getText().trim());
            //Get selected item combobox TypeID
            Object item = cbTypeID.getSelectedItem();
            supplier.setSuppliertypeID(Integer.parseInt(((ComboItem) item).getValue()));
            //Insert data
            if (flag.equals("insert")) {
                if(checkName && checkAddress && checkEmail && checkPhone){
                    if (SupplierManager.checkName(jtfSuppList_Name.getText().trim()) == null) {
                        boolean result = SupplierManager.insert(supplier);

                        if (result) {
                            JOptionPane.showMessageDialog(this, "Insert Successfully!", "Message", JOptionPane.INFORMATION_MESSAGE);
                            loadData();
                            jdSuppList_InsertUpdate.dispose();
                        } else {
                            JOptionPane.showMessageDialog(this, "Insert Failed!", "Message", JOptionPane.ERROR_MESSAGE);
                        } 
                    } else {
                            JOptionPane.showMessageDialog(this, "Existing Supplier Name!", "Message", JOptionPane.ERROR_MESSAGE);
                    }
                } else {
                    jdSuppList_Notification.setVisible(true);
                    jdSuppList_Notification.pack();
                            
                    ImageIcon correctIcon = new javax.swing.ImageIcon(getClass().getResource("/com/image/032.png"));
                    ImageIcon falseIcon = new javax.swing.ImageIcon(getClass().getResource("/com/image/033.png"));

                    jlblStatus_Name.setIcon(checkName ? correctIcon : falseIcon);
                    jlblStatus_Email.setIcon(checkEmail ? correctIcon : falseIcon);
                    jlblStatus_Address.setIcon(checkAddress ? correctIcon : falseIcon);
                    jlblStatus_Phone.setIcon(checkPhone ? correctIcon : falseIcon);
                }
                       
                } else if (flag.equals("update")){  
                    if(checkName && checkAddress && checkPhone && checkEmail){
                        supplier.setSupplierID(Integer.parseInt(String.valueOf(tableModel.getValueAt(jtbSupplierList.getSelectedRow(), 0))));
                        boolean result = SupplierManager.update(supplier);
                        
                        if (result) {
                            JOptionPane.showMessageDialog(this, "Update Successfully!", "Message", JOptionPane.INFORMATION_MESSAGE);
                            loadData();
                            jdSuppList_InsertUpdate.dispose();
                        } else {
                            JOptionPane.showMessageDialog(this, "Update Failed!", "Message", JOptionPane.ERROR_MESSAGE);
                        }
                    } else {
                        jdSuppList_Notification.setVisible(true);
                        jdSuppList_Notification.pack();

                        ImageIcon correctIcon = new javax.swing.ImageIcon(getClass().getResource("/com/image/032.png"));
                        ImageIcon falseIcon = new javax.swing.ImageIcon(getClass().getResource("/com/image/033.png"));

                        jlblStatus_Name.setIcon(checkName ? correctIcon : falseIcon);
                        jlblStatus_Email.setIcon(checkEmail ? correctIcon : falseIcon);
                        jlblStatus_Address.setIcon(checkAddress ? correctIcon : falseIcon);
                        jlblStatus_Phone.setIcon(checkPhone ? correctIcon : falseIcon);
                        }  
                    }
        } catch (SQLException ex) {
            System.err.println(ex.getMessage());    
        } catch (Exception ex) {
            Logger.getLogger(SupplierList.class.getName()).log(Level.SEVERE, null, ex);
        } 
    }//GEN-LAST:event_jbtSuppList_SubmitActionPerformed

    /* Update data */
    private void jbtUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtUpdateActionPerformed
        // TODO add your handling code here:
        flag = "update";
        clearForm();
        if (jtbSupplierList.getSelectedRowCount() == 1) {
            jdSuppList_InsertUpdate.setVisible(true);
            jdSuppList_InsertUpdate.pack();
            jdSuppList_InsertUpdate.setLocationRelativeTo(null);

            try{
                ResultSet resultSet = SupplierManager.displayAllRows();
                resultSet.absolute(jtbSupplierList.getSelectedRow() + 1);
                jtfSuppList_Name.setText(resultSet.getString(2).trim());
                jtaSuppList_Address.setText(resultSet.getString(4).trim());
                jtfSuppList_Phone.setText(resultSet.getString(5).trim());
                jtfSuppList_Email.setText(resultSet.getString(6).trim());
                cbTypeID.setSelectedIndex(SupplierManager.checkTypeIDByTypeName(resultSet.getString(3)).getSupplierTypeID());
            }catch(SQLException ex){
                System.err.println(ex.getMessage());
            }   
        } else {
            JOptionPane.showMessageDialog(null, "Please choose a record to update!", "Message", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jbtUpdateActionPerformed

    /* Delete data */
    private void jbtDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtDeleteActionPerformed
        // TODO add your handling code here:
        if (jtbSupplierList.getSelectedRowCount() == 1) {
            int reply = JOptionPane.showConfirmDialog(null, "Do you want to delete this record?", "Message",
                    JOptionPane.INFORMATION_MESSAGE);
            if (reply == JOptionPane.YES_OPTION) {
                try {
                    ResultSet resultSet = SupplierManager.displayAllRows();
                    resultSet.absolute(jtbSupplierList.getSelectedRow() + 1);
                    resultSet.deleteRow();
                    loadData();
                } catch (SQLException ex) {
                    Logger.getLogger(SupplierList.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }else{
            JOptionPane.showMessageDialog(null, "Please choose a record to delete!", "Message", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jbtDeleteActionPerformed

    private void jtfSuppList_NameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfSuppList_NameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtfSuppList_NameActionPerformed

    /* Load data to table */
    DefaultTableModel tableModel;
    private void loadData() {
        tableModel = (DefaultTableModel) jtbSupplierList.getModel();
        tableModel.setRowCount(0);
        try {
            ResultSet resultSet = SupplierManager.displayAllRows();

            while (resultSet.next()) {
                Vector vector = new Vector();
                vector.add(String.valueOf(resultSet.getInt(1)).trim());
                vector.add(resultSet.getString(2).trim());
                vector.add(resultSet.getString(3).trim());
                vector.add(resultSet.getString(4).trim());
                vector.add(resultSet.getString(5).trim());
                vector.add(resultSet.getString(6).trim());

                tableModel.addRow(vector);
            }
            // Fill data into combobox cbTypeID
            if (cbTypeID.getItemCount() == 0) {
                ResultSet rsTypeID = SupplierManager.getTypeID();
                while (rsTypeID.next()) {
                    cbTypeID.addItem(new SupplierList.ComboItem(rsTypeID.getString(2), String.valueOf(rsTypeID.getInt(1)).trim()));
                }
            }
        } catch (SQLException ex) {
            Logger.getLogger(SupplierList.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /* Clear form */
    private void clearForm() {
        jtfSuppList_Name.setText(null);
        jtaSuppList_Address.setText(null);
        jtfSuppList_Phone.setText(null);
        jtfSuppList_Email.setText(null);
        cbTypeID.setSelectedIndex(0);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SupplierList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SupplierList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SupplierList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SupplierList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new SupplierList().setVisible(true);
                } catch (Exception ex) {
                    Logger.getLogger(SupplierList.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbTypeID;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbtDelete;
    private javax.swing.JButton jbtInsert;
    private javax.swing.JButton jbtSuppList_Reset;
    private javax.swing.JButton jbtSuppList_Submit;
    private javax.swing.JButton jbtUpdate;
    private javax.swing.JDialog jdSuppList_InsertUpdate;
    private javax.swing.JDialog jdSuppList_Notification;
    private javax.swing.JLabel jlblAddress;
    private javax.swing.JLabel jlblEmail;
    private javax.swing.JLabel jlblName;
    private javax.swing.JLabel jlblPhone;
    private javax.swing.JLabel jlblStatus_Address;
    private javax.swing.JLabel jlblStatus_Email;
    private javax.swing.JLabel jlblStatus_Name;
    private javax.swing.JLabel jlblStatus_Phone;
    private javax.swing.JLabel jlblSuppList_Address;
    private javax.swing.JLabel jlblSuppList_Email;
    private javax.swing.JLabel jlblSuppList_Name;
    private javax.swing.JLabel jlblSuppList_Phone;
    private javax.swing.JLabel jlblSuppList_TypeID;
    private javax.swing.JTextArea jtaSuppList_Address;
    private javax.swing.JTable jtbSupplierList;
    private javax.swing.JTextField jtfSuppList_Email;
    private javax.swing.JTextField jtfSuppList_Name;
    private javax.swing.JTextField jtfSuppList_Phone;
    // End of variables declaration//GEN-END:variables

}
